import { editAPI } from '@/apis/area'

export default {
  /**
   * 约定：
  * data,methods ,computed里面变量和方法名统统以edit开头
   */
  data() {
    return {
      editDialogFormData: {
        type: 'edit',
        id: null,
        dialogVisible: false,
        title: '编辑区域',
        form: {
          areaName: '', // 区域名称
          spaceNumber: '', // 车位数（个）
          areaProportion: '', // 面积（㎡）
          ruleId: 4, // 计费规则
          remark: '', //备注

        }
      }
    }
  },
  beforeCreate() {
    this.editCopyDetailForm = {} //记录后端返回的数据，重置的时候用到
  },
  methods: {
    editResetFrom() {
      const editCopyDetailForm = this.editCopyDetailForm
      const form = this.editDialogFormData.form
      Object.keys(form).forEach(key => form[key] = editCopyDetailForm[key])
    },
    editGetDetail(row) {
      this.editCopyDetailForm = JSON.parse(JSON.stringify(row))
      this.editDialogFormData.id = row.id
      const form = this.editDialogFormData.form
      Object.keys(form).forEach(key => form[key] = row[key])
      this.editDialogFormData.dialogVisible = true
    },
    async editComfirmForm() {
      const params = this.editDialogFormData.form
      params.id=this.editDialogFormData.id
      try {
        const r = await editAPI(params)
        this.$message.success('编辑成功')
        this.fetchTableData()
      } catch (error) {
        this.$message.error(error.msg || '编辑失败')

      }

    }
  },
  mounted() {
  }
}